package com.haiya.factory.simple.pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author qiaoguoqiang
 */
public class PizzaStore {
//    public PizzaStore() {
//        Pizza pizza = null;
//        /**
//         * 订购的Pizza类型
//         */
//        String orderType;
//
//        do {
//            /**
//             *  orderType = "greek";
//             *  这里我们不写死，通过一个方法来动态获取系统输入作为订购的Pizza类型
//             */
//            orderType = getOrderType();
//            if (orderType.equals("greek")) {
//                pizza = new GreekPizz();
//                pizza.setName("希腊披萨");
//            } else if (orderType.equals("cheese")) {
//                pizza = new CheesePizza();
//                pizza.setName("奶酪披萨");
//            } else if (orderType.equals("pan")) {
//                pizza = new PanPizza();
//                pizza.setName("烤盘披萨");
//            } else {
//                break;
//            }
//
//            /**
//             * 输出Pizza制作过程
//             */
//            pizza.prepare();
//            pizza.bake();
//            pizza.cut();
//            pizza.box();
//        } while (true);
//    }

    SimplePizzaFactory simpleFactory;
    Pizza pizza = null;

    public PizzaStore(SimplePizzaFactory simpleFactory) {
        this.simpleFactory = simpleFactory;
        makePizza();
    }

    public void makePizza() {
        String orderType = "";
        do {
            orderType = getOrderType();
            pizza = this.simpleFactory.createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购Pizza失败");
                break;
            }
        } while (true);
    }
    private String getOrderType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type: ");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
